package cn.imjzm.runcarserve.exception;

import cn.imjzm.runcarserve.pojo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    public Result ex(Exception ex) {
        // 记录异常堆栈
        logger.error("系统发生异常: ", ex);

        return Result.error("操作失败，请联系管理员");
    }
}
